using System;
using System.IO;
using System.Web;

namespace NopSolutions.NopCommerce.LuceneHelper
{
    public class DirectoryManager
    {
        public static DirectoryInfo GetIndex(LuceneIndexType indexType)
        {
            DirectoryInfo directoryInfo;
            switch (indexType)
            {
                case LuceneIndexType.Product:
                    directoryInfo = new DirectoryInfo(HttpContext.Current.Server.MapPath(Globals.PRODUCT_INDEX));
                    break;
                case LuceneIndexType.Category:
                    directoryInfo = new DirectoryInfo(HttpContext.Current.Server.MapPath(Globals.CATEGORY_INDEX));
                    break;
                case LuceneIndexType.SpecificaitonOptions:
                    directoryInfo = new DirectoryInfo(HttpContext.Current.Server.MapPath(Globals.SPEC_OPTION_INDEX));
                    break;
                case LuceneIndexType.SpecificationAttributes:
                    directoryInfo = new DirectoryInfo(HttpContext.Current.Server.MapPath(Globals.SPEC_ATTRIBUTE_INDEX));
                    break;
                default:
                    throw new Exception("index type " + Enum.GetName(typeof (LuceneIndexType), indexType) +
                                        " was not cared for.");
            }
            if (!directoryInfo.Exists)
                directoryInfo.Create();
            return directoryInfo;
        }
    }
}
